/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {Thrift} from '@ohos/thrift'
import CalculatorClient from '../../common/calculator/Calculator';
import {WorkI16, Operation
} from '../../common/calculator/tutorial_types';

export default {
    data: {
        i16add: '',
        i16subtract: '',
        i16multiply: '',
        i16divide: ''
    },
    onInit() {
    },
    onButtonClick() {
        var transport = new Thrift.Transport("http://192.168.0.109:9090/thrift/service/tutorial/");
        var protocol = new Thrift.Protocol(transport);
        var client = new CalculatorClient(protocol);

        var that = this;

        var workI16Add = new WorkI16()
        workI16Add.num1 = 10;
        workI16Add.num2 = 15;
        workI16Add.op = Operation.ADD;
        client.calculateI16(1, workI16Add, function (result) {
            if (result) {
                that.i16add = result;
            }
        });

        var workI16Subtract = new WorkI16()
        workI16Subtract.num1 = 10;
        workI16Subtract.num2 = 15;
        workI16Subtract.op = Operation.SUBTRACT;
        client.calculateI16(1, workI16Subtract, function (result) {
            if (result) {
                that.i16subtract = result;
            }
        });

        var workI16Multiply = new WorkI16()
        workI16Multiply.num1 = 15;
        workI16Multiply.num2 = 15;
        workI16Multiply.op = Operation.MULTIPLY;
        client.calculateI16(1, workI16Multiply, function (result) {
            if (result) {
                that.i16multiply = result;
            }
        });

        var workI16Divide = new WorkI16()
        workI16Divide.num1 = 15;
        workI16Divide.num2 = 15;
        workI16Divide.op = Operation.DIVIDE;
        client.calculateI16(1, workI16Divide, function (result) {
            if (result) {
                that.i16divide = result;
            }
        });
    }
}
